﻿#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <iostream>
#include <string>

#include "connect.h"

void allRelationTest( ShallowSymantic & ss, SQLBIGINT objId ){
	std::vector< SQLBIGINT > allRelations = ss.searchRelations( objId, ShallowSymantic::RelationLeft );

	std::wcout << L"Объекты связанные с " << objId << std::endl;
	for( size_t i = 0; i < allRelations.size(); i++ ){
		std::wcout << allRelations[i] << std::endl;
	}

	std::vector< std::wstring > parsedChain = ss.parseChain( allRelations );

	for( size_t i = 0; i < parsedChain.size(); i++ ){
		std::wcout << parsedChain[i] << std::endl;
	}
}

void searchRelationTest( ShallowSymantic & ss, SQLBIGINT leftObjId, SQLBIGINT rightObjId ){
	std::vector< SQLBIGINT > searchedRelations = ss.searchRelations( leftObjId, ShallowSymantic::RelationLeft, rightObjId );

	std::wcout << L"Цепочка связи между объектами " << leftObjId << L" и " << rightObjId << std::endl;
	for( size_t i = 0; i < searchedRelations.size(); i++ ){
		std::wcout << searchedRelations[i] << std::endl;
	}

	std::vector< std::wstring > parsedChain = ss.parseChain( searchedRelations );

	for( size_t i = 0; i < parsedChain.size(); i++ ){
		std::wcout << parsedChain[i] << std::endl;
	}
}

void main(){
	setlocale(LC_ALL,"");

	std::wstring database = L"objects";
	std::wstring user = L"sysdba";
	std::wstring password = L"masterkey";

	ShallowSymantic join;

	join.connect(database, user, password);

	std::wcout << L"Тест поиска всех возможных отношений: " << std::endl;
	allRelationTest( join, 7 );
	std::wcout << std::endl;

	std::wcout << L"Тест поиска отношений между двумя объектами: " << std::endl;
	searchRelationTest( join, 7, 10 );
	std::wcout << std::endl;

	join.disconnect();

	system ("pause");
}

